package game;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class GameListener implements KeyListener, ActionListener, MouseMotionListener, MouseListener{
	private GameField gameField;
	
	public GameListener(GameField gf){
		gameField = gf;
	}
	
	@Override
	public void mouseClicked(MouseEvent arg0) {}

	@Override
	public void mouseEntered(MouseEvent arg0) {}

	@Override
	public void mouseExited(MouseEvent arg0) {}

	@Override
	public void mousePressed(MouseEvent arg0) {}

	@Override
	public void mouseReleased(MouseEvent arg0) {}

	@Override
	public void mouseDragged(MouseEvent arg0) {}

	@Override
	public void mouseMoved(MouseEvent arg0) {}

	@Override
	public void actionPerformed(ActionEvent arg0) {}

	@Override
	public void keyPressed(KeyEvent ke) {
		handleTankDirection(ke, true);
	}

	@Override
	public void keyReleased(KeyEvent ke) {
		handleTankDirection(ke, false);
	}

	@Override
	public void keyTyped(KeyEvent arg0) {}
	
	private void handleTankDirection(KeyEvent ke, boolean move){
		switch(ke.getKeyCode()){
		case KeyEvent.VK_D:
			gameField.moveTank("right", move);
			break;
		case KeyEvent.VK_A:
			gameField.moveTank("left", move);
			break;
		case KeyEvent.VK_W:
			gameField.moveTank("forward", move);
			break;
		case KeyEvent.VK_S:
			gameField.moveTank("reverse", move);
			break;
		}
	}

}
